﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d50_brdjMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d50_brdj_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d50_brdjMgr mgr = new d50_brdjMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d50_brdj(e.Parameters[d50_brdj_Filter.ParamPrefix]));
            IList<d50_brdj> list = mgr.FindAllByPage_d50_brdj(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d50_brdj_Filter.ParamPrefix]);
            d50_brdj_MainStore.DataSource = list;
            d50_brdj_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d50_brdjMgr mgr = new d50_brdjMgr();
            RowSelectionModel sm = d50_brdj_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d50_brdj _d50_brdj = new d50_brdj();
                _d50_brdj.zyid = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d50_brdj(_d50_brdj))
                {
                    log.Debug("d50_brdj中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d50_brdj_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d50_brdjMgr mgr = new d50_brdjMgr();
            d50_brdj _d50_brdj = new d50_brdj();
            if (Hid.Text.Length > 0)
                _d50_brdj = mgr.FindById_d50_brdj(int.Parse(Hid.Text));
            
			_d50_brdj.zybh = Txtzybh.Text.Trim();
			_d50_brdj.mzbh = Txtmzbh.Text.Trim();
			_d50_brdj.zycs = int.Parse(TxtNumzycs.Text.Trim());
			_d50_brdj.brlxid = Txtbrlxid.Text.Trim();
			_d50_brdj.gfbh = Txtgfbh.Text.Trim();
			_d50_brdj.brxm = Txtbrxm.Text.Trim();
			_d50_brdj.xbid = Txtxbid.Text.Trim();
			_d50_brdj.brnl = Txtbrnl.Text.Trim();
			_d50_brdj.csrq = Txtcsrq.Text.Trim();
			_d50_brdj.yebz = Txtyebz.Text.Trim();
			_d50_brdj.hyzkmc = Txthyzkmc.Text.Trim();
			_d50_brdj.hyid = Txthyid.Text.Trim();
			_d50_brdj.csddmc = Txtcsddmc.Text.Trim();
			_d50_brdj.mzmc = Txtmzmc.Text.Trim();
			_d50_brdj.gjid = Txtgjid.Text.Trim();
			_d50_brdj.sfzh = Txtsfzh.Text.Trim();
			_d50_brdj.gzdw = Txtgzdw.Text.Trim();
			_d50_brdj.dwdh = Txtdwdh.Text.Trim();
			_d50_brdj.dwyb = Txtdwyb.Text.Trim();
			_d50_brdj.hkdz = Txthkdz.Text.Trim();
			_d50_brdj.hkyb = Txthkyb.Text.Trim();
			_d50_brdj.lxrm = Txtlxrm.Text.Trim();
			_d50_brdj.gxid = Txtgxid.Text.Trim();
			_d50_brdj.lxdz = Txtlxdz.Text.Trim();
			_d50_brdj.lxdh = Txtlxdh.Text.Trim();
			_d50_brdj.ryksid = Txtryksid.Text.Trim();
			_d50_brdj.ryksmc = Txtryksmc.Text.Trim();
			_d50_brdj.rybs = Txtrybs.Text.Trim();
			_d50_brdj.rycw = Txtrycw.Text.Trim();
			_d50_brdj.rysj = Txtrysj.Text.Trim();
			_d50_brdj.rybqid = Txtrybqid.Text.Trim();
			_d50_brdj.zkbqid = Txtzkbqid.Text.Trim();
			_d50_brdj.cyksid = Txtcyksid.Text.Trim();
			_d50_brdj.cyksmc = Txtcyksmc.Text.Trim();
			_d50_brdj.cybs = Txtcybs.Text.Trim();
			_d50_brdj.cycw = Txtcycw.Text.Trim();
			_d50_brdj.cysj = Txtcysj.Text.Trim();
			_d50_brdj.zyts = int.Parse(TxtNumzyts.Text.Trim());
			_d50_brdj.mzzd = Txtmzzd.Text.Trim();
			_d50_brdj.ryzd = Txtryzd.Text.Trim();
			_d50_brdj.ryqzsj = Txtryqzsj.Text.Trim();
			_d50_brdj.zyzt = Txtzyzt.Text.Trim();
			_d50_brdj.yzxs = Txtyzxs.Text.Trim();
			_d50_brdj.yzzj = Txtyzzj.Text.Trim();
			_d50_brdj.qfje = Txtqfje.Text.Trim();
			_d50_brdj.fdje = Txtfdje.Text.Trim();
			_d50_brdj.etys = Txtetys.Text.Trim();
			_d50_brdj.mzys = Txtmzys.Text.Trim();
			_d50_brdj.hlzt = Txthlzt.Text.Trim();
			_d50_brdj.cwbz = Txtcwbz.Text.Trim();
			_d50_brdj.qfjsbz = Txtqfjsbz.Text.Trim();
			_d50_brdj.qfjsje1 = Txtqfjsje1.Text.Trim();
			_d50_brdj.qfjsje = Txtqfjsje.Text.Trim();
			_d50_brdj.jssj = Txtjssj.Text.Trim();
			_d50_brdj.lsh = Txtlsh.Text.Trim();
			_d50_brdj.cyzd = Txtcyzd.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d50_brdj(_d50_brdj);
            else
                isok = mgr.Add_d50_brdj(_d50_brdj);
            if (isok)
            {
                d50_brdj_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d50_brdj中执行了保存（插入或修改），并成功");
                d50_brdj_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}